﻿using System;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class StatisticData_DiagnoseBottleneck_DiagnoseBottleneck : System.Web.UI.Page
{
    DiagnoseBottleneck dbn;
    private DateTime starttime
    {
        get { return DateTime.Parse(ViewState["starttime"].ToString()); }
        set { ViewState["starttime"] = value; }
    }
    private DateTime stoptime
    {
        get { return DateTime.Parse(ViewState["stoptime"].ToString()); }
        set { ViewState["stoptime"] = value; }
    }

    public StatisticData_DiagnoseBottleneck_DiagnoseBottleneck()
    {
        dbn = new DiagnoseBottleneck();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            starttime = DateTime.Parse(this.TextBox1.Value.Trim());
            stoptime = DateTime.Parse(this.TextBox2.Value.Trim());
        }
        catch(FormatException)
        {
            string str1 = "请检查输入的日期时间格式是否正确";
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str1 + "');</script>");  
        }
        BindQ_dt_pt(starttime, stoptime);
        BindQ_pt_tm(starttime, stoptime);
        BindQ_tm_pt(starttime, stoptime);
        BindCount(starttime, stoptime);
    }

    protected void BindCount(DateTime starttime, DateTime stoptime)
    {
        int Q_dt_pt=0;
        int Q_pt_tm=0; 
        int Q_tm_pt=0;
        foreach (ProductType_QInfo item in dbn.GetQ_dt_pt(starttime, stoptime))
        {
            Q_dt_pt += item.Quantity;
        }
        this.HyperLink1.Text = Q_dt_pt.ToString();
        foreach (ProductType_QInfo item in dbn.GetQ_pt_tm(starttime, stoptime))
        {
            Q_pt_tm += item.Quantity;
        }
        this.HyperLink2.Text = Q_pt_tm.ToString();
        foreach (ProductType_QInfo item in dbn.GetQ_tm_pt(starttime, stoptime))
        {
            Q_tm_pt += item.Quantity;
        }
        this.HyperLink3.Text = Q_tm_pt.ToString();
    }

    protected void BindQ_dt_pt(DateTime starttime, DateTime stoptime)
    {
        this.GridView1.DataSource = dbn.GetQ_dt_pt(starttime, stoptime);
        this.GridView1.DataBind();
    }

    protected void BindQ_pt_tm(DateTime starttime, DateTime stoptime)
    {
        this.GridView4.DataSource = dbn.GetQ_pt_tm(starttime, stoptime);
        this.GridView4.DataBind();
    }

    protected void BindQ_tm_pt(DateTime starttime, DateTime stoptime)
    {
        this.GridView5.DataSource = dbn.GetQ_tm_pt(starttime, stoptime);
        this.GridView5.DataBind();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindQ_dt_pt(starttime, stoptime);
    }

    protected void GridView4_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView4.PageIndex = e.NewPageIndex;
        BindQ_pt_tm(starttime, stoptime);
    }

    protected void GridView5_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView5.PageIndex = e.NewPageIndex;
        BindQ_tm_pt(starttime, stoptime);
    }
}
